<?php session_start();
$_SESSION['uid'] = 1;
header("Location: http://localhost:82/ndtho-web1/file.php?uid=".$_SESSION['uid']);
?>
<?php
require_once './data/users.php';
?>
<form method="post">
    Username <input type="text" name="username" required><p>
        Password <input type="password" name="password"required><p>
        <input type="submit" name="submit">
</form>
<?php if (isset($_POST['submit'])): ?>
    <?php
    $username = $_POST['username'];
    $password = $_POST['password'];
    $isOk = FALSE;
    $index = -1;

    for ($i = 0; $i < count($users); $i++) {
        if ((strcmp($users[$i]['username'], $username) == 0) && (strcmp($users[$i]['password'], $password) == 0)) {
            $isOk = TRUE;
            $index = $i;
            $_SESSION = $index;
        }
    }
    if($isOk){
        header("Location: http://localhost:82/ndtho-web1/file.php?uid=".$users[$index]['id']);
    }
    else{
        'Đăng thất bại';
    }
    ?>
<?php endif; ?>
